package com.wva.video.service.impl;

import com.wva.common.constant.BucketNameConst;
import com.wva.common.enums.ObjectName;
import com.wva.minio.utils.MinIOUtils;
import com.wva.video.domain.vo.VideoItemDTO;
import com.wva.video.service.VideoCoverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: hong
 * @Date: 2025/3/4 17:56:37
 */
@Service
public class VideoCoverServiceImpl implements VideoCoverService {
    @Autowired
    MinIOUtils minIOUtils;

    @Override
    public String getUrlByVideoId(Long videoId) {
        String endpoint = minIOUtils.getEndpoint();
        String coverObjectName = ObjectName.COVER.format(videoId);
        String coverUrl = String.format("%s/%s%s", endpoint, BucketNameConst.STATIC, coverObjectName);
        return coverUrl;
    }

    @Override
    public VideoItemDTO wrapVideoItemVOWithCoverUrl(VideoItemDTO videoItemDTO) {
        videoItemDTO.setCoverUrl(getUrlByVideoId(videoItemDTO.getId()));
        return videoItemDTO;
    }
}
